# The stemplot displayed from the above code would be what you would do "by hand" if asked.
# The stemplot displayed from the above code would be what you would do "by hand" if asked.
stem(so2data$co2)
stem(co2data$co2)
co2data=read.csv(file.choose(co2.csv), header=TRUE)
co2 <- read.table("C:/Users/Cadell/SkyDrive/Classes/Statistics for Engineers/Data Analysis #1/co2.csv", quote="\"", comment.char="")
View(co2)
stem(co2)
co2data = read.csv(file.choose(), header=TRUE
View(co2)
View(co2)
View(co2)
co2data = read.csv(file.choose(), header=TRUE)
View(co2)
View(co2)
# Finally, we divide by the sample size of 20 to get the proportion.
cardio_data = read.csv(file.choose(), header=TRUE)
head(cardio_data)
stem(cardio_data$heartrate)
stem(cardio_data$heartrate, scale=2)
range(cardio_data$heartrate)
112 - 78
summary(cardio_data$heartrate)
sd(cardio_data$heartrate)
sum(cardio_data$heartrate > 97) / 20
co2data = read.csv(file.choose(), header=TRUE)
head(co2data)
hist(co2data$co2)
stem(co2data$co2)
hist(co2data$co2, main = "Annual Carbon Dioxide Emissions in 2007", col = "purple",
xlab = "Annual emissions (metric tons per person)")
boxplot(co2data$co2)
boxplot(co2data$co2, main = "Annual Carbon Dioxide Emissions in 2007", col = "green",
ylab = "Annual emissions (metric tons per person)")
boxplot(co2data$co2, main = "Annual Carbon Dioxide Emissions in 2007", col = "green",
horizontal = TRUE, xlab = "Annual emissions (metric tons per person)")
summary(co2data$co2)
sd(co2data$co2)
speed_data = read.csv(file.choose(), header=TRUE)
head(speed_data)
speed_data
summary(speed_data$PercentFatalities[speed_data$Speed=="Retained"])
sd(speed_data$PercentFatalities[speed_data$Speed=="Retained"])
summary(speed_data$PercentFatalities[speed_data$Speed=="Increased"])
sd(speed_data$PercentFatalities[speed_data$Speed=="Increased"])
1-pt(1.6,7)
1-pt(3.3,11)
1-pt(-.6,26)
#This first line, once you run the code, will open up a window
#which will allow you to search for your .csv file. Double click
#on the correct file. Once your data set appears under "Data"
#under the Global Environment pane, you must then attach the file.
sun = read.csv(file.choose(), header= TRUE)
#Check Out first 6 lines Data
head(sun)
# Make a Boxplot
boxplot(sun$spots, main= "Boxplot of Sunspots
boxplot(sun$spots, main= "Boxplot of Sunspots duirng Spanish colonial times", xlab = "Mean number of sunspots in a 4-week period", horizontal = TRUE, col = "blue")
boxplot(sun$spots, main= "Boxplot of Sunspots duirng Spanish colonial times",
xlab = "Mean number of sunspots in a 4-week period", horizontal = TRUE, col = "blue")
# Get Mean
mean(sun$spots)
# Get Satndard Deviation
sd(sun$spots)
#Get Sample Size
length(sun$spots)
# Perform t Test
t.test(sun$spots, mu=41, alternative = "greater")
min(5,4)
t-stat(min(5,4))
sd(1,2,3,4)
fueldata = read.csv(file.choose(), header= TRUE)
head(fueldata)
USMean = mean(fueldata$CombFE[fueldata$International=="American"])
USMean
USStdDev = sd(fueldata$CombFE[fueldata$International=="American"])
USStdDev
USsamplesize = length(fueldata$CombFE[fueldata$International=="American"])
USsamplesize
INTMean = mean(fueldata$CombFE[fueldata$International=="International"])
INTMean
INTStdDev = sd(fueldata$CombFE[fueldata$International=="International"])
INTStdDev
INTsamplesize = length(fueldata$CombFE[fueldata$International=="International"])
INTsamplesize
t.test(fueldata$CombFE ~ fueldata$International, conf.level=0.90)
table(fueldata$International, fueldata$Guzzler)
boxplot(fueldata$EPACalculatedAnnualFuelCost~fueldata$Fuel, horizontal = TRUE, col= "light blue",
xlab="Annual Fuel Cost", ylab="Fuel Type",
main = "Estimated Annual Fuel Costs for \n 2016 Vehicles among Fuel Types")
mod = aov(fueldata$EPACalculatedAnnualFuelCost ~ fueldata$Fuel)
summary(mod)
TukeyHSD(mod, conf.level = 0.95)
#Upload Data: Data file is EpaFE2016DataEDITED.csv
mpgdata = read.csv(file.choose(), header = TRUE)
#Look at data
head(mpgdata)
# Attach Data Set! Very Important Step!
# This allows you to not call the variable every time! Remember before we used something like dataset$variablename
# By attaching, R will know to search for variable names automatically in the data set you attach
# CAUTION: Only attach and work with one data set at a time! If you attach two data sets with some of the same variable
# names within them, it is confusing as to which data set R will go to for the variable called.
attach(mpgdata)
# Create a scatterplot to visualize the relationship between CityFE and HwyFE
plot(CityFE, HwyFE, main = "Relationship between City Fuel Efficiency
and Highway Fuel Efficiency", xlab = "CityFE for 2016 Vehicles", ylab = "Highway FE", pch=16)
# Calculate the correlation coefficient between CityFE and HwyFE
cor(CityFE, HwyFE)
# Obtain the least squares regression line and t test for the slope p-value
mod = lm(HwyFE~CityFE)
summary(mod)
# Calculate the 95% CI for the slope.
confint(mod, level = 0.95)
# Plot the residuals for the analysis between CityFE and HwyFE
plot(CityFE, mod$residuals, main = "Residuals", pch=16)
abline(h = 0, lty =2, lwd = 2)
# Create a scatterplot to visualize the relationship between CityFE and HwyFE
# add least squares regression line to plot
plot(CityFE, HwyFE, main = "Relationship between City Fuel Efficiency
and Highway Fuel Efficiency", xlab = "CityFE for 2016 Vehicles", ylab = "Highway FE", pch=16)
abline(mod$coef[1], mod$coef[2], lwd = 2,col = "blue")
# Predict the Highway FE when City FE is 25.
predict(mod, data.frame(CityFE = 25))
# Calculate a 95% confidence interval for when the Highway FE when City FE is 25.
predict(mod, data.frame(CityFE = 25), interval = "confidence", level = 0.95)
# Calculate a 95% prediction interval for when the Highway FE when City FE is 25.
predict(mod, data.frame(CityFE = 25), interval = "prediction", level = 0.95)
library(Sleuth3)
"setup"
setwd("D:/CAV-Reduced")
AV = read.csv("AV.csv");
HV = read.csv("HV.csv");
par(mfrow=c(1,2))
"plot headway"
plot(AV$speedmph~AV$headft,
xlab="Distance Headway (ft)",
ylab="Speed (mph)",
main="AV Speed vs Distance Headway")
plot(HV$speedmph~HV$headft,
xlab="Distance Headway (ft)",
ylab="Speed (mph)",
main="HV Speed vs Distance Headway")
plot(AV$speedmph~AV$headft,
xlab="Distance Headway (ft)",
ylab="Speed (mph)",
main="AV Speed vs Distance Headway",
ylim=c(25,80), xlim=c(0,1200))
plot(HV$speedmph~HV$headft,
xlab="Distance Headway (ft)",
ylab="Speed (mph)",
main="HV Speed vs Distance Headway",
ylim=c(25,80), xlim=c(0,1200))
"setup"
setwd("D:/CAV-Reduced")
AV = read.csv("AV.csv");
HV = read.csv("HV.csv");
par(mfrow=c(1,2))
"plot seperate"
headwayAV<-density(AV$headft)
plot(headwayAV,main="AV Headway (ft)")
polygon(headwayAV,col="gray")
speedAV<-density(AV$speedmph)
plot(speedAV,main="AV Speed (mph)")
polygon(speedAV,col="gray")
headwayHV<-density(HV$headft)
plot(headwayHV,main="HV Headway (ft)")
polygon(headwayHV,col="gray")
speedHV<-density(HV$speedmph)
plot(speedHV,main="HV Speed (mph)")
polygon(speedHV,col="gray")
"plot together"
plot(headwayAV,main="Headway (ft)",col="red")
lines(headwayHV,col="blue")
plot(speedHV,main="Speed (mph)",col="blue")
lines(speedAV,col="red")
densityAV<-density(AV$densityvpmpl)
plot(densityAV,main="AV Density (vpmpl)")
densityHV<-density(HV$densityvpmpl)
plot(densityHV,main="HV Density (vpmpl)")
par(mfrow=c(1,1))
plot(densityHV,main="Density (vpmpl)",col="blue")
lines(densityAV,col="red")
legend(3, 30, legend=c("Line 1", "Line 2"),
col=c("red", "blue"), lty=1:2, cex=0.8)
legend(3, 30, legend=c("densityHV", "densityAV"),
col=c("red", "blue"), lty=1:2, cex=0.8)
par(mfrow=c(1,1))
plot(densityHV,main="Density (vpmpl)",col="blue")
lines(densityAV,col="red")
legend(3, 30, legend=c("densityHV", "densityAV"),
col=c("red", "blue"), lty=1:2, cex=0.8)
legend(3, 30, legend=c(densityHV, densityAV),
col=c("red", "blue"), lty=1:2, cex=0.8)
legend('topright', names(a)[-1] ,
lty=1, col=c('red', 'blue', 'green',' brown'),
bty='n', cex=.75)
legend(70, .03, legend=c(densityHV, densityAV),
col=c("red", "blue"), lty=1:2, cex=0.8)
legend(70,0.05,legend=c(densityHV,densityAV),
col=c("red","blue"), lty=1:2,cex=0.8)
legend(70,0.05,legend=c("densityHV",densityAV),
col=c("red","blue"), lty=1:2,cex=0.8)
legend(70,0.05,legend=c("densityHV","densityAV"),
col=c("red","blue"), lty=1:2,cex=0.8)
legend(70,0.05,legend=c("densityHV","densityAV"),
col=c("red","blue"), lty=1:2,cex=0.8)
plot(densityHV,main="Density (vpmpl)",col="blue")
lines(densityAV,col="red")
legend(70,0.05,legend=c("densityHV","densityAV"),
col=c("red","blue"), lty=1:2,cex=0.8)
legend(60,0.05,legend=c("densityHV","densityAV"),
col=c("red","blue"), lty=1:2,cex=0.8)
plot(densityHV,main="Density (vpmpl)",col="blue")
lines(densityAV,col="red")
legend(65,0.05,legend=c("densityHV","densityAV"),
col=c("red","blue"), lty=1:2,cex=0.8)
legend(65,0.05,legend=c("densityHV","densityAV"),
col=c("blue","red"), cex=0.8)
legend(65,0.05,legend=c("densityHV","densityAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
plot(headwayAV,main="Headway (ft)",col="red")
lines(headwayHV,col="blue")
legend(1000,0.004,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
plot(speedHV,main="Speed (mph)",col="blue")
lines(speedAV,col="red")
legend(75,0.06,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
legend(1000,0.005,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"setup"
setwd("D:/CAV-Reduced")
AV = read.csv("AV.csv");
HV = read.csv("HV.csv");
par(mfrow=c(1,2))
"plot seperate"
headwayAV<-density(AV$headft)
plot(headwayAV,main="AV Headway (ft)")
speedAV<-density(AV$speedmph)
plot(speedAV,main="AV Speed (mph)")
headwayHV<-density(HV$headft)
plot(headwayHV,main="HV Headway (ft)")
speedHV<-density(HV$speedmph)
plot(speedHV,main="HV Speed (mph)")
"plot together"
plot(headwayAV,main="Headway (ft)",col="red")
lines(headwayHV,col="blue")
legend(1000,0.004,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
plot(speedHV,main="Speed (mph)",col="blue")
lines(speedAV,col="red")
legend(75,0.06,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"plot density"
densityAV<-density(AV$densityvpmpl)
plot(densityAV,main="AV Density (vpmpl)")
densityHV<-density(HV$densityvpmpl)
plot(densityHV,main="HV Density (vpmpl)")
par(mfrow=c(1,1))
plot(densityHV,main="Density (vpmpl)",col="blue")
lines(densityAV,col="red")
legend(65,0.05,legend=c("densityHV","densityAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
legend(900,0.004,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"plot together"
plot(headwayAV,main="Headway (ft)",col="red")
lines(headwayHV,col="blue")
legend(900,0.004,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
plot(speedHV,main="Speed (mph)",col="blue")
lines(speedAV,col="red")
legend(65,0.06,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"setup"
setwd("D:/CAV-Reduced")
AV = read.csv("AV.csv");
HV = read.csv("HV.csv");
par(mfrow=c(1,2))
"plot seperate"
headwayAV<-density(AV$headft)
plot(headwayAV,main="AV Headway (ft)")
speedAV<-density(AV$speedmph)
plot(speedAV,main="AV Speed (mph)")
headwayHV<-density(HV$headft)
plot(headwayHV,main="HV Headway (ft)")
speedHV<-density(HV$speedmph)
plot(speedHV,main="HV Speed (mph)")
"plot together"
plot(headwayAV,main="Headway (ft)",col="red")
lines(headwayHV,col="blue")
legend(900,0.004,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
plot(speedHV,main="Speed (mph)",col="blue")
lines(speedAV,col="red")
legend(65,0.06,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"plot density"
densityAV<-density(AV$densityvpmpl)
plot(densityAV,main="AV Density (vpmpl)")
densityHV<-density(HV$densityvpmpl)
plot(densityHV,main="HV Density (vpmpl)")
par(mfrow=c(1,1))
plot(densityHV,main="Density (vpmpl)",col="blue")
lines(densityAV,col="red")
legend(65,0.05,legend=c("densityHV","densityAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
AV = read.csv("AV.csv");
View(AV)
View(AV)
timeheadAV<-density(AV$timeheads)
plot(timeheadAV,main="AV Time Headway (s)")
timeheadHV<-density(HV$timeheads)
plot(timeheadHV,main="HV Time Headway (s)")
par(mfrow=c(1,1))
plot(timeheadHV,main="Time Headway (s)",col="blue")
lines(timeheadAV,col="red")
legend(65,0.05,legend=c("timeheadHV","timeheadAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
setwd("D:/CAV-Reduced")
AV = read.csv("AV.csv");
HV = read.csv("HV.csv");
par(mfrow=c(1,2))
"plot time headway"
timeheadAV<-density(AV$timeheads)
plot(timeheadAV,main="AV Time Headway (s)")
timeheadHV<-density(HV$timeheads)
plot(timeheadHV,main="HV Time Headway (s)")
par(mfrow=c(1,1))
plot(timeheadHV,main="Time Headway (s)",col="blue")
lines(timeheadAV,col="red")
legend(65,0.05,legend=c("timeheadHV","timeheadAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
timeheadAV<-density(AV$timeheads)
plot(timeheadAV,main="AV Time Headway (s)")
timeheadHV<-density(HV$timeheads)
plot(timeheadHV,main="HV Time Headway (s)")
par(mfrow=c(1,1))
plot(timeheadHV,main="Time Headway (s)",col="blue")
lines(timeheadAV,col="red")
legend(65,0.05,legend=c("timeheadHV","timeheadAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
setwd("D:/CAV-Reduced")
AV = read.csv("AV.csv");
HV = read.csv("HV.csv");
par(mfrow=c(1,2))
"plot seperate"
headwayAV<-density(AV$headft)
plot(headwayAV,main="AV Headway (ft)")
speedAV<-density(AV$speedmph)
plot(speedAV,main="AV Speed (mph)")
headwayHV<-density(HV$headft)
plot(headwayHV,main="HV Headway (ft)")
speedHV<-density(HV$speedmph)
plot(speedHV,main="HV Speed (mph)")
"plot together"
plot(headwayAV,main="Headway (ft)",col="red")
lines(headwayHV,col="blue")
legend(900,0.004,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
plot(speedHV,main="Speed (mph)",col="blue")
lines(speedAV,col="red")
legend(65,0.06,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"plot time headway"
timeheadAV<-density(AV$timeheads)
plot(timeheadAV,main="AV Time Headway (s)")
timeheadHV<-density(HV$timeheads)
plot(timeheadHV,main="HV Time Headway (s)")
par(mfrow=c(1,1))
plot(timeheadHV,main="Time Headway (s)",col="blue")
lines(timeheadAV,col="red")
legend(65,0.05,legend=c("timeheadHV","timeheadAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"setup"
setwd("D:/CAV-Reduced")
AV = read.csv("AV.csv");
HV = read.csv("HV.csv");
par(mfrow=c(1,2))
"plot headway"
plot(AV$speedmph~AV$headft,
xlab="Distance Headway (ft)",
ylab="Speed (mph)",
main="AV Speed vs Distance Headway")
plot(AV$speedmph~AV$headft,
xlab="Distance Headway (ft)",
ylab="Speed (mph)",
main="AV Speed vs Distance Headway")
plot(AV$speedmph~AV$headft,
xlab="Distance Headway (ft)",
ylab="Speed (mph)",
main="AV Speed vs Distance Headway",
ylim=c(25,80), xlim=c(0,1200))
plot(HV$speedmph~HV$headft,
xlab="Distance Headway (ft)",
ylab="Speed (mph)",
main="HV Speed vs Distance Headway",
ylim=c(25,80), xlim=c(0,1200))
"setup"
setwd("D:/CAV-Reduced")
AV = read.csv("AV.csv");
HV = read.csv("HV.csv");
par(mfrow=c(1,2))
"plot seperate"
headwayAV<-density(AV$headft)
plot(headwayAV,main="AV Headway (ft)")
speedAV<-density(AV$speedmph)
plot(speedAV,main="AV Speed (mph)")
headwayHV<-density(HV$headft)
plot(headwayHV,main="HV Headway (ft)")
speedHV<-density(HV$speedmph)
plot(speedHV,main="HV Speed (mph)")
"plot together"
plot(headwayAV,main="Headway (ft)",col="red")
lines(headwayHV,col="blue")
legend(900,0.004,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
plot(speedHV,main="Speed (mph)",col="blue")
lines(speedAV,col="red")
legend(65,0.06,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"plot time headway"
timeheadAV<-density(AV$timeheads)
plot(timeheadAV,main="AV Time Headway (s)")
timeheadHV<-density(HV$timeheads)
plot(timeheadHV,main="HV Time Headway (s)")
par(mfrow=c(1,1))
plot(timeheadHV,main="Time Headway (s)",col="blue")
lines(timeheadAV,col="red")
legend(65,0.05,legend=c("timeheadHV","timeheadAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
par(mfrow=c(1,1))
plot(timeheadHV,main="Time Headway (s)",col="blue")
lines(timeheadAV,col="red")
legend(12,0.3,legend=c("timeheadHV","timeheadAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"setup"
setwd("D:/CAV-Reduced")
AV = read.csv("AV.csv");
HV = read.csv("HV.csv");
par(mfrow=c(1,2))
"plot seperate"
headwayAV<-density(AV$headft)
plot(headwayAV,main="AV Headway (ft)")
speedAV<-density(AV$speedmph)
plot(speedAV,main="AV Speed (mph)")
headwayHV<-density(HV$headft)
plot(headwayHV,main="HV Headway (ft)")
speedHV<-density(HV$speedmph)
plot(speedHV,main="HV Speed (mph)")
"plot together"
plot(headwayAV,main="Headway (ft)",col="red")
lines(headwayHV,col="blue")
legend(900,0.004,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
plot(speedHV,main="Speed (mph)",col="blue")
lines(speedAV,col="red")
legend(65,0.06,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"plot time headway"
timeheadAV<-density(AV$timeheads)
plot(timeheadAV,main="AV Time Headway (s)")
timeheadHV<-density(HV$timeheads)
plot(timeheadHV,main="HV Time Headway (s)")
par(mfrow=c(1,1))
plot(timeheadHV,main="Time Headway (s)",col="blue")
lines(timeheadAV,col="red")
legend(12,0.3,legend=c("timeheadHV","timeheadAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"setup"
setwd("D:/CAV-Reduced")
AV = read.csv("AV.csv");
HV = read.csv("HV.csv");
par(mfrow=c(1,2))
"plot seperate"
headwayAV<-density(AV$headft)
plot(headwayAV,main="AV Headway (ft)")
speedAV<-density(AV$speedmph)
plot(speedAV,main="AV Speed (mph)")
headwayHV<-density(HV$headft)
plot(headwayHV,main="HV Headway (ft)")
speedHV<-density(HV$speedmph)
plot(speedHV,main="HV Speed (mph)")
"plot together"
plot(headwayAV,main="Headway (ft)",col="red")
lines(headwayHV,col="blue")
legend(900,0.004,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
plot(speedHV,main="Speed (mph)",col="blue")
lines(speedAV,col="red")
legend(65,0.06,legend=c("headwayHV","headwayAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
"plot time headway"
timeheadAV<-density(AV$timeheads)
plot(timeheadAV,main="AV Time Headway (s)")
timeheadHV<-density(HV$timeheads)
plot(timeheadHV,main="HV Time Headway (s)")
par(mfrow=c(1,1))
plot(timeheadHV,main="Time Headway (s)",col="blue")
lines(timeheadAV,col="red")
legend(12,0.3,legend=c("timeheadHV","timeheadAV"),
col=c("blue","red"), lty=1:1,cex=0.8)
